import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Pages from "vite-plugin-pages";
import { resolve } from "path";
import PurgeIcons from "vite-plugin-purge-icons";

function pathResolve(dir: string) {
  return resolve(__dirname, ".", dir);
}
// https://vitejs.dev/config/
export default defineConfig({
  // resolve: {
  //   alias: [
  //     {
  //       // /@/xxxx  =>  src/xxx
  //       find: /^\/@\//,
  //       replacement: pathResolve("src") + "/",
  //     },
  //     {
  //       // /#/xxxx  =>  types/xxx
  //       find: /^\/#\//,
  //       replacement: pathResolve("types") + "/",
  //     },
  //   ],
  // },

  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },

  server: {
    port: 8888,
    proxy: {
      "/api": {
        target: "http://localhost:8000",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "/src"),
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    Pages({
      extensions: ["vue", "ts", "tsx"],
    }),
    PurgeIcons({
      /* PurgeIcons Options */
    }),
  ],
});
